# Replication Files for "Ballots & Burials"

The included files replicate the analyses in 'Ballots and burials: Electoral turnovers and the health costs of elections during emergencies', by Max Schaub, Héloïse Cloléry, Guillaume Kon Kam King, and Davide Morisi; Journal of Politics.

Most of the tables and figures are replicated by running the do-file ballots&burials.do in Stata. To reproduce them, open the do-file in Stata and follow the instructions in the file. 

The rest of the code is written in R. To reproduce it, you can open & run the master script `ballots&burials.R`. The script calls all other R-scripts in order & allows you to selectively re-run specific parts.

The datasets are described in the Codebook.

## Setup 

For the Stata analyses, StataNow, Version 18.5 was used. 

For the analyses in R, we use `renv` to guarantee full reproducibility. You can install all dependencies from the master script, or do so manually with

```
source("renv/activate.R")
renv::restore()
```

This will allow you to re-run the code with the exact same R and package versions as we did. If `renv` is not working for you or you would like to install the packages into your system library, you can also run the script `Code/dependencies.R` to install dependencies.

## Scripts

* `generate_excess_mortality_data.R`: calls the preprocessing, estimation & postprocessing scripts for the Variational Inference-routine in order:
    - `vb_preprocess.R`
    - `vb_estimate.R`
    - `vb_postprocess.R`

* `fig*.R`: Create the corresponding figures in the `Figures/`-folder.
* `helper_functions.R` & `silent.R`: utility scripts with some custom functions used throughout.
* `dependencies.R`: backup script to install dependencies if renv fails or user prefers system wide installation.

## Notes 

* The replication code for the file "Data/Population_data_extrapolated.rds" is available and documented at Morisi D, Cloléry H, Kon Kam King G, Schaub M (2024) How COVID-19 affects voting for incumbents: Evidence from local elections in France. PLoS ONE 19(3): e0297432. <https://doi.org/10.1371/journal.pone.0297432>
